package com.boc.ewr.util;

import org.jeecg.common.system.api.ISysBaseAPI;
import org.jeecg.common.system.vo.LoginUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;

import javax.annotation.PostConstruct;
import java.util.*;

/**
 * @author : Wzz
 * @create : 2023-05- 06- 10:19
 * @desc :
 */
@Component
public class ToUserUtil {

    @Autowired
    private ISysBaseAPI sysBaseApi;

    private static ISysBaseAPI sysBaseApiStatic;

    @PostConstruct
    public void init() {
        sysBaseApiStatic = sysBaseApi;
    }

    public static String genToUser(Set<String> orgNoSet) {
        if(orgNoSet == null  || orgNoSet.size() ==0 ){
            return null;
        }
        // 初始化接收用户IdList
        Set<String> allSendUserNameList = new HashSet<>();

        for (String branchNo : orgNoSet) {
            // 根据机构号查询机构下所有员工UserName
            Set<String> userNameSetByOrgCode = sysBaseApiStatic.getUserNameSetByOrgCode(branchNo);
            if (userNameSetByOrgCode != null && userNameSetByOrgCode.size() > 0) {
                allSendUserNameList.addAll(userNameSetByOrgCode);
            }
        }
        if (allSendUserNameList.size() > 0) {
            // 拼接UserName
            StringJoiner stringJoiner = new StringJoiner(",");
            for (String str : allSendUserNameList) {
                stringJoiner.add(str);
            }
            return stringJoiner.toString();
        } else {
            return null;
        }
    }
}
